package com.yztstudy.Controller;

import com.yztstudy.Service.AdminCategoryService;
import com.yztstudy.entity.Category;
import com.yztstudy.param.PageParam;
import com.yztstudy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类别管理的表示层
 */

@RestController
public class AdminCategoryController {

    @Autowired
    private AdminCategoryService adminCategoryService;


    /**
     * TODO 分页展示类别
     * @param pageParam 分页参数
     * @return
     */
    @GetMapping("/category/list")
    public R listPage(PageParam pageParam)
    {
        return adminCategoryService.listPage(pageParam);
    }


    /**
     * TODO 新增类别
     * @param category 类别对象
     * @return
     */
    @PostMapping("/category/save")
    public R saveCategory(Category category)
    {
        return adminCategoryService.saveCategory(category);
    }


    /**
     * TODO 删除类别
     * @param categoryId 类别Id
     * @return
     */
    @PostMapping("/category/remove")
    public R removeCategory(Integer categoryId)
    {
        return adminCategoryService.removeCategory(categoryId);
    }


    /**
     * TODO 更新类别
     * @param category 类别对象
     * @return
     */
    @PostMapping("/category/update")
    public R updateCategory(Category category)
    {
        return adminCategoryService.updateCategory(category);
    }
}
